package com.hxl.aop.service.impl;

//import com.baomidou.dynamic.datasource.annotation.DS;
//import com.baomidou.dynamic.datasource.annotation.Slave;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxl.aop.entity.SysUser;
import com.hxl.aop.mapper.UserMapper;
import com.hxl.aop.res.DataSource;
import com.hxl.aop.res.annotation.Log;
import com.hxl.aop.res.enums.BusinessType;
import com.hxl.aop.res.enums.OperatorType;
import com.hxl.aop.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 霍帅帅
 * @since 2024-07-23 22:14
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, SysUser> implements UserService {

    @Autowired
    private UserMapper userMapper;

    /*@Override
    @DS("slave") *//* 和@Slave作用相同 *//*
    @Slave
    public List<SysUser> list(SysUser sysUser) {
        QueryWrapper<SysUser> qw = new QueryWrapper<>();
        qw.eq("user_type", sysUser.getUserType());
        List<SysUser> sysUserList = super.list(qw);

        return sysUserList;
    }*/

    @Transactional(readOnly = true)
    @DataSource(name = "MASTER")
    public List<SysUser> list(SysUser sysUser) {
        QueryWrapper<SysUser> qw = new QueryWrapper<>();
        qw.eq("user_type", sysUser.getUserType());
        List<SysUser> sysUserList = super.list(qw);

        return sysUserList;
    }

    @Transactional(readOnly = true)
    @DataSource(name = "SLAVE")
    public List<SysUser> listS(SysUser sysUser) {
        QueryWrapper<SysUser> qw = new QueryWrapper<>();
        qw.eq("user_type", sysUser.getUserType());
        List<SysUser> sysUserList = super.list(qw);

        return sysUserList;
    }
}
